package org.example.message.生产;

import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @Auther:Liu
 * @Testname:tongbu
 * @Date:2025/8/22 14:54
 */
public class tongBu {
    @SneakyThrows
    public static void main(String[] args) {
        // 1.创建消息生产者 producer，并指定生产者组名
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_a");
        // 2.指定 NameSrv 地址
        producer.setNamesrvAddr("192.168.10.88:9876");
        // 3.启动 producer
        producer.start();
        // 4.创建消息对象，指定 Topic、Tag 和消息体
        String topic = "topic_a";
        String tag = "sync";
        String body = "1234";
        Message message = new Message(topic, tag, body.getBytes());
        // 5.发送消息
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult);
        // 6.关闭生产者 producer
        producer.shutdown();
    }
}
